package com.relife.core.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "sys_role")
public class RoleEntity extends BaseEntity {

	/**
	 * @author WU
	 * @date 2016年5月16日 上午11:47:00
	 */
	private static final long serialVersionUID = 3429472673953652878L;
	/** 角色名称 */
	private String name;
	/** 职务编码 */
	private String dutyCode;
	/** 对应流程 groupId **/
	private String groupId;

	private DepartmentEntity depart;
	private List<UserRoleEntity> userRoleList;
	private List<FunctionEntity> functionList;
	private List<RolePermissionEntity> rolePerList;
	private List<HomeSettingEntity> homeSetList;

	public RoleEntity() {

	}

	public RoleEntity(String id) {
		super.setId(id);
	}

	@Column(name = "NAME")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "DUTY_CODE")
	public String getDutyCode() {
		return dutyCode;
	}

	public void setDutyCode(String dutyCode) {
		this.dutyCode = dutyCode;
	}

	public String getGroupId() {
		return groupId;
	}

	public void setGroupId(String groupId) {
		this.groupId = groupId;
	}
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "DEPART_ID")
	public DepartmentEntity getDepart() {
		return depart;
	}

	public void setDepart(DepartmentEntity depart) {
		this.depart = depart;
	}

	@OneToMany(mappedBy = "role", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
	public List<UserRoleEntity> getUserRoleList() {
		return userRoleList;
	}

	public void setUserRoleList(List<UserRoleEntity> userRoleList) {
		this.userRoleList = userRoleList;
	}

	@ManyToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
	@JoinTable(name = "sys_function_role", joinColumns = { @JoinColumn(name = "role_id") }, inverseJoinColumns = { @JoinColumn(name = "fun_id") })
	public List<FunctionEntity> getFunctionList() {
		return functionList;
	}

	public void setFunctionList(List<FunctionEntity> functionList) {
		this.functionList = functionList;
	}

	@OneToMany(mappedBy = "role", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
	public List<RolePermissionEntity> getRolePerList() {
		return rolePerList;
	}

	public void setRolePerList(List<RolePermissionEntity> rolePerList) {
		this.rolePerList = rolePerList;
	}

	@OneToMany(mappedBy = "role", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
	public List<HomeSettingEntity> getHomeSetList() {
		return homeSetList;
	}

	public void setHomeSetList(List<HomeSettingEntity> homeSetList) {
		this.homeSetList = homeSetList;
	}

}
